package com.pine.app.module.security.core.userdetails;


import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author xiaoyuan
 * @create 2019/9/6 15:44
 **/
@Data
public class User implements UserDetails {

    private String password;
    private final String username;
    private final Set<String> resources;
    private final Set<String> roles;
    private final boolean accountNonExpired;
    private final boolean accountNonLocked;
    private final boolean credentialsNonExpired;
    private final boolean enabled;
    private final String id;

    private final Map<String, Object> otherInfo = new HashMap<>();



    public User(String id, String username, String password, boolean enabled, boolean accountNonExpired
            , boolean credentialsNonExpired, boolean accountNonLocked, Set<String> resources, Set<String> roles) {
        if (StringUtils.isNotEmpty(username)) {
            this.username = username;
            this.password = password;
            this.enabled = enabled;
            this.accountNonExpired = accountNonExpired;
            this.credentialsNonExpired = credentialsNonExpired;
            this.accountNonLocked = accountNonLocked;
            this.resources = resources;
            this.roles = roles;
            this.id = id;
        } else {
            throw new IllegalArgumentException("Cannot pass null or empty values to constructor");
        }
    }


    public User(String id, String username, String password, Set<String> resources, Set<String> roles) {
        this(id, username,
                password, false, true, true, true, resources, roles);
    }
}
